#include "RB_ADC.h"



RB_ADC::RB_ADC(void)
{
   pinMode(A6,INPUT);
   pinMode(12,OUTPUT);    //A  
   pinMode(13,OUTPUT);    //B
   pinMode(7,OUTPUT);     //C  
   digitalWrite(12, LOW);
   digitalWrite(13, LOW);
   digitalWrite(7, LOW);
}
uint8_t  RB_ADC::RB_ADC_Read(uint8_t port)
{
   
        switch(port)
          { 
            
            case 4: // 000   A0
                 digitalWrite(7, LOW);      //ADC_C
                 digitalWrite(13, LOW);     //ADC_B
                 digitalWrite(12, LOW);     //ADC_A
                 delay(10);
                return(ADC_Read()); 
                break;     
            case 3: //001    A1
                 digitalWrite(7, LOW);      //ADC_C
                 digitalWrite(13, LOW);     //ADC_B
                 digitalWrite(12, HIGH);     //ADC_A
                delay(10);
                return(ADC_Read()); 
                break;   
            case 1: //4     A4
                digitalWrite(7, HIGH);      //ADC_C
                digitalWrite(13, LOW);     //ADC_B
                digitalWrite(12, LOW);     //ADC_A
                delay(10);
                return(ADC_Read()); 
                break;  
            case 2: //6     A6
                 digitalWrite(7, HIGH);      //ADC_C
                 digitalWrite(13, HIGH);     //ADC_B
                 digitalWrite(12, LOW);     //ADC_A
                delay(10);
                return(ADC_Read()); 
                break;  
           default:
                
                break; 
          }            
}

uint8_t  RB_ADC::ADC_Read(void)
{        

 
        uint32_t       value = 0;


        value = analogRead(A6);
 
    
 
        if(value>981)
            return None_Device;
        else if(value>938)
            return Other_Device;
        else if(value>895) 
            return Other_Device;
        else if(value>852)
            return Servo_Device;
        else if(value>809)
            return DC_Motor_Device;
        else if(value>766)
            return Temp_And_Humi_Sensor;
        else if(value>724)
            return Other_Device;
        else if(value>660)
            return Ultrasonic_Distance_Sensor;
        else if(value>637)
            return Other_Device;
        else if(value>594)
            return Other_Device;
        else if(value>551)
            return Sound_Sensor;
        else if(value>490)
            return LED_Matraix_Blue;
        else if(value>465)
            return Other_Device;
        else if(value>422)
            return Other_Device;
        else if(value>379)
            return Light_Sensor;
        else if(value>336)
            return Other_Device;
        else if(value>293)
            return Other_Device;
        else if(value>250)
            return Other_Device;
        else if(value>207)
            return Line_Follower_Sensor;
        else if(value>164)
            return Other_Device;
        else if(value>121)
            return Other_Device;
        else if(value>78)
            return Other_Device;
        else if(value>35)
            return Other_Device;
        else 
            return Other_Device;

}

